/**
 * @BelongsProject : LeetCode
 * @Author : WXY
 * @CreateTime : 2022-12-08  19:23
 * @Description :剑指 Offer 28. 对称的二叉树
 * @Version : 1.0
 */

public class Num028_isSymmetric {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    public static boolean isSymmetric(TreeNode root) {
        if (root == null)return true;
        return process(root.left, root.right);
    }

    private static boolean process(TreeNode left, TreeNode right) {
        if (left == null && right == null) return true;
        if (left == null || right == null) return false;
        if (left.val != right.val) return false;
        return process(left.left, right.right) && process(left.right, right.left);
    }


}
